package com.wyh.controller.groupfour.proprietor;

import com.wyh.common.result.Result;
import com.wyh.domain.dto.groupfour.customerDTO.AddInvoiceHeaderDTO;
import com.wyh.domain.dto.groupfour.customerDTO.UpdateInvoiceHeaderDTO;
import com.wyh.domain.dto.depositDTO.DepositHistoryByIdDTO;
import com.wyh.domain.dto.depositDTO.DepositHistoryDTO;
import com.wyh.domain.vo.gruopfour.myProprietorVO.MyPaymentRecordVO;
import com.wyh.domain.vo.gruopfour.myProprietorVO.PayDataVO;
import com.wyh.domain.vo.gruopfour.myVO.*;

import com.wyh.domain.vo.gruopfour.threemeterVO.PageResult;
import com.wyh.service.appservice.IMyService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

import static com.wyh.common.enums.ResultCodeEnum.SYSTEM_ERROR;

//我的
@RestController
@RequestMapping("/my")
@Api(tags = "业主端‘我的’接口")
public class MyController {

    @Autowired
    private IMyService myService;


    //点击"缴款"数据接口

    @GetMapping("/{customerId}")
    @ApiOperation("缴费通知端列表接口")
    public Result<PageResult<PayDataVO>> my(@PathVariable @ApiParam("客户id") Integer customerId,
                                                    @RequestParam(defaultValue = "1") int pageNum,
                                                    @RequestParam(defaultValue = "5") int pageSize) {
        PageResult<PayDataVO> payData = myService.getPayData(customerId, pageNum, pageSize);
        if (payData == null) {
            return Result.error(SYSTEM_ERROR);
        }

        return Result.success(payData);
    }


    //账单信息接口 bill

    @GetMapping("/bill/{id}")
    @ApiOperation("账单信息接口")
    public Result<BillInformationVO> bill(@PathVariable @ApiParam("账单id") Integer id) {
        BillInformationVO billData = myService.getBillData(id);
        if (billData == null) {
            return Result.error(SYSTEM_ERROR);
        }
        return Result.success(billData);
    }

    @GetMapping("/payment/{customerId}")
    @ApiOperation("缴费记录接口")
    public Result<PageResult<MyPaymentRecordVO>> payment(@PathVariable @ApiParam("客户id") Integer customerId,
                                                   @RequestParam(defaultValue = "1") int pageNum,
                                                   @RequestParam(defaultValue = "5") int pageSize) {
        PageResult<MyPaymentRecordVO> paymentRecord = myService.getPaymentRecord(customerId, pageNum, pageSize);

        if (paymentRecord == null) {
            return Result.error(SYSTEM_ERROR);
        }
        return Result.success(paymentRecord);
    }

    @GetMapping("/invoice/{id}")
    @ApiOperation("发票列表接口")
    public Result<PageResult<InvoiceHeaderVO>> invoice(@PathVariable @ApiParam("客户id") Integer id,
                                                       @RequestParam(defaultValue = "1") int pageNum,
                                                       @RequestParam(defaultValue = "5") int pageSize) {
        PageResult<InvoiceHeaderVO> invoiceHeaderList = myService.getInvoiceHeaderList(id, pageNum, pageSize);
        if (invoiceHeaderList == null) {
            return Result.error(SYSTEM_ERROR);
        }
        return Result.success(invoiceHeaderList);
    }

    @PostMapping("/invoice/add")
    @ApiOperation("添加发票接口")
    public Result<String> addInvoice(@RequestBody AddInvoiceHeaderDTO invoiceheader) {

        return Result.success(myService.addInvoiceHeader(invoiceheader));
    }

    @PutMapping("/invoice/update")
    @ApiOperation("修改发票接口")
    public Result<String> updateInvoice(@RequestBody UpdateInvoiceHeaderDTO invoiceheader) {
        return Result.success(myService.updateInvoiceHeader(invoiceheader));
    }

    @GetMapping("/billdetails/{billId}")
    @ApiOperation("账单明细接口")
    public Result<List<BillDetailsVO>> billdetails(@PathVariable @ApiParam("账单id") Integer billId) {
        List<BillDetailsVO> billDetails = myService.getBillDetails(billId);
        if (billDetails == null) {
            return Result.error(SYSTEM_ERROR);
        }
        return Result.success(billDetails);
    }

    /**
     * 押金历史数据接口
     */
    @GetMapping("/deposit")
    @ApiOperation("保证金历史数据接口")
    public Result<List<DepositHistoryVO>> deposit(DepositHistoryDTO depositHistoryDTO) {
        return Result.success(myService.getDepositHistory(depositHistoryDTO));
    }


   @GetMapping("/depositData")
    @ApiOperation("根据保证金类型查询保证金历史数据接口")
    public Result<List<DepositHistoryVO>> depositData(DepositHistoryByIdDTO depositHistoryByIdDTO) {
        return Result.success(myService.getDepositHistoryByType(depositHistoryByIdDTO));
    }

    @GetMapping("/PrepaidAccountInformation/{id}")
    @ApiOperation("预存账户信息接口")
    public Result<List<PrepaidAccountVO>> PrepaidAccountInformation(@PathVariable @ApiParam("账单id")  Integer id) {
        return Result.success(myService.getAccountResourceInformation(id));
    }

    //通用余额历史数据接口
    @GetMapping("/generalBalanceHistory/{id}")
    @ApiOperation("通用余额历史数据接口")
    public Result<List<BalanceHistoryVO>> generalBalanceHistory(@PathVariable @ApiParam("资源id")  Integer id) {
        return Result.success(myService.getGeneralBalanceHistory(id));
    }

    //特殊余额历史数据接口
    @GetMapping("/specialBalanceHistory/{id}")
    @ApiOperation("水电气余额历史数据接口")
    public Result<List<BalanceHistoryVO>> specialBalanceHistory(@PathVariable @ApiParam("资源id") Integer id) {
        return Result.success(myService.getSpecialBalanceHistory(id));
    }



}
